const puppeteer =  require("puppeteer");

async function requestpage (){
    // 启动浏览器  
    const browser = await puppeteer.launch({ headless: false });  
    // 创建一个新页面  
    const page = await browser.newPage();
    // 访问一个网址  
    await page.goto('https://google.com');
    await page.type('textarea[name=q]', 'gentlebands\n');

    return new Promise((res, rej)=>{
        setTimeout(async () => {
            try{
                await page.click('a[data-pcu]')
    
                setTimeout(async () => {
                    console.log( await page.content())
                }, 5000);
    
                page.close()

                res()
            } catch(e) {
                console.log(e)
                res()
            }
    
            
        }, 2000);
    })
    // 关闭浏览器  
    // await browser.close();  
 };  

function wait(t){
    return new Promise((res, rej)=>{
        setTimeout(() => {
            res()
        }, t);
    })
 }

 (async ()=>{
    while(1){
       await requestpage();
       await wait(3000)
    }
 })()